<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="box">
        <button>首页</button>
        <button>第二页</button>
        <button>最后一页</button>
    </div>
    <div class="coment"></div>
</body>

</html>
<script>
    var arr = [
        { lujing: '/qwer', coment: shouye },
        { lujing: '/asdf', coment: dierye },
        { lujing: '/zxcv', coment: zuihouyiye },
    ]
    var btns = [...document.querySelectorAll('button')]
    btns.forEach(function (item, index) {
        item.onclick = (e) => {
            e.preventDefault()
            history.pushState({}, '', arr[index].lujing)
            arr[index].coment()
        }
    })
    function shouye() {
        document.querySelector('.coment').innerHTML = `首页
        
        `
    }
    function dierye() {
        document.querySelector('.coment').innerHTML = `第二页
        
        `
    }
    function zuihouyiye() {
        document.querySelector('.coment').innerHTML = `最后一页
        
        `
    }
</script>